import 'package:flutter/material.dart';
import 'package:gold/base/provider_scaffold.dart';
import 'package:gold/model/express_company_model.dart';
import 'package:gold/ui/my/settings/express/set_express_viewmodel.dart';
import 'package:gold/utils/res.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';
import 'package:provider/provider.dart';

/// @description: 自行寄快递页面
/// @author tangzhentao
/// @created at 19:32 2025/3/8

class SetExpressPage extends StatelessWidget {
  /// 订单id
  final int orderId;
  /// 是否店铺订单
  final bool isShopOrder;

  const SetExpressPage({super.key, required this.orderId, this.isShopOrder = false});

  @override
  Widget build(BuildContext context) {
    return ProviderScaffold<SetExpressViewmodel>(
      resizeToAvoidBottomInset: false,
      appBar: (_) => xfgAppbar(title: '自行寄快递'),
      model: SetExpressViewmodel(orderId, isShopOrder),
      builder: (ctx, express) => Column(
        children: [
          strokeHeightContainer,
          Container(
            margin: EdgeInsets.fromLTRB(XfgSize().size10, XfgSize().size10, XfgSize().size10, 0),
            height: XfgSize().size52,
            padding: EdgeInsets.symmetric(horizontal: XfgSize().size12),
            alignment: Alignment.centerLeft,
            decoration: BoxDecoration(color: XfgColor.white, borderRadius: BorderRadius.vertical(top: Radius.circular(XfgSize().size6))),
            child: TextField(
              keyboardType: TextInputType.text,
              style: TextStyle(fontSize:XfgSize().text18, color: XfgColor.text1D),
              maxLines: 1,
              controller: express.controller,
              focusNode: express.expressNuNode,
              onChanged: express.onTextChanged,
              decoration: InputDecoration(
                  isCollapsed: true,
                  isDense: true,
                  border: InputBorder.none,
                  contentPadding: EdgeInsets.zero,
                  hintStyle: TextStyle(fontSize: XfgSize().text18, color: XfgColor.text3),
                  hintText: '点击填写快递单号'
              ),
            ),
          ),
          strokeHeightContainer,
          GestureDetector(
            onTap: express.pickupCompany,
            child: Container(
              margin: EdgeInsets.symmetric(horizontal: XfgSize().size10),
              height: XfgSize().size52,
              padding: EdgeInsets.symmetric(horizontal: XfgSize().size12),
              alignment: Alignment.centerLeft,
              decoration: BoxDecoration(color: XfgColor.white, borderRadius: BorderRadius.vertical(bottom: Radius.circular(XfgSize().size6))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Builder(builder: (con) {
                    final company = con.select<SetExpressViewmodel, Company?>((k) => k.company);
                    return XfgText(company?.expName?? '自动匹配快递公司', fontSize: XfgSize().text18, color: company?.expName?.isNotEmpty == true ? XfgColor.text1D:XfgColor.text3);
                  }),
                  Image.asset(Res.imagesArrowRight, width: XfgSize().size10, height: XfgSize().size15)
                ],
              ),
            ),
          ),
          const Spacer(),
          Builder(builder: (con) {
            final canClick = con.select<SetExpressViewmodel, bool>((k) => k.canClick);
            return TextButton(
              onPressed: canClick? express.setExpress:null,
              style: xfgButtonStyle(Size(XfgSize().size342, XfgSize().size50), radius: XfgSize().size50),
              child: XfgText('确认提交', color: XfgColor.white, fontSize: XfgSize().text18),
            );
          }),
          bottomNavigatorWidget
        ],
      ),
    );
  }

}
